package sysu.el.graph.undi;

import sysu.el.graph.Edge;
import sysu.el.graph.GraphConstants;

public class UndiMEGTAdjList extends UndiGTAdjList {
	
	public UndiMEGTAdjList(int nodeNum) {
		super(nodeNum);
	}
	
	public UndiMEGTAdjList(int edgeNum, Edge[] edgeList) {
		super( edgeNum, edgeList);
	}
	
	private int index[][];
	public void establishIndex(){
		this.index = new int[this.getNodeNum()][this.getNodeNum()+1];
		for (int i=0; i<this.getNodeNum(); i++){
			int counter = 0;
			int edgeNum = this.getDegree(i);
			int list[] = this.adjNodes[i].elements();
			for (int j=0; j<this.getNodeNum(); j++){
				while ((list[counter] < j) && (counter < edgeNum))	counter ++;
				this.index[i][j] = counter; 
			}
			this.index[i][this.getNodeNum()] = edgeNum;
		}
	}
	
	public int getEdgeList(int i, int j, int[] arr){
		assert(i<this.getNodeNum());
		assert(j<this.getNodeNum());
		int s = this.index[i][j];
		int e = this.index[i][j+1];
		int counter = e - s;
		int list[] = this.adjNodes[i].elements();
		for (int k=0; i<counter; i++){
			arr[k] = list[s+k];
		}
		return counter;
	}
	
	public int[] getEdgeList(int i, int j){
		assert(i<this.getNodeNum());
		assert(j<this.getNodeNum());
		int s = this.index[i][j];
		int e = this.index[i][j+1];
		int counter = e - s;
		/** new arr */
		int arr[] = new int[counter];
		int list[] = this.adjNodes[i].elements();
		for (int k=0; i<counter; i++){
			arr[k] = list[s+k];
		}
		return arr;
	}
	
//	public int getLEdgeW(int i, int j){
////		return this.adjWei[i][this.index[i][j]];
////		return this.w[i][j];
//		return this.
//	}
	
//	public int getREdgeW(int i, int j){
//		if (this.w[i][j] == GraphConstants.NULL_EDGE)
//			return GraphConstants.NULL_EDGE;
//		return this.adjWei[i][this.index[i][j+1]-1];
//	}
	
	
	public int leftId;
	public int rightId;
	public void getEdgeID(int i, int j){
		this.leftId = this.index[i][j];
		this.rightId =  this.index[i][j+1];
	}
}
